<template>
	<view style="padding: 30rpx;background-color: #fff;margin-top: 10rpx;">
		<view class="title">
			<text style="margin-left: 20rpx;" v-if="helplistdata.length>0">已邀请{{helplistdata.length}}位好友助力，中奖倍率增加{{multiple}}倍</text> 
			<swiper class="swiper" vertical="true" autoplay="true" disable-touch="true" v-else>
				<swiper-item>
					<view>邀请<text class="redfont">1</text>位好友，中奖率超过<text class="redfont">100%</text>的用户</view>
				</swiper-item>
				<swiper-item >
					<view>每邀请<text class="redfont">1</text>位好友助力，中奖倍率增加<text class="redfont">{{boostdata.boost_multiple}}</text>倍</view>
				</swiper-item>
			</swiper>
			<image src="/static/image/question.png" style="width: 32rpx;height: 32rpx" @click="opentip"></image>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in friend" :key="index">
				<view v-if="helplistdata[index]">
					<image :src="helplistdata[index].avatar"></image>
					<text class="nickname">{{helplistdata[index].nickname}}</text>
				</view>
				<view v-else>
					<image src='/static/image/headgrey.png'></image>
					<text class="nickname">待邀请</text>
					<text class="multiple">+1倍</text>
				</view>
				
			</view>

			<view class="item" @click="gotorank">
				<image src="/static/image/morefriend.png"></image>
				<text class="nickname">更多</text>
				<text class="multiple">+N倍</text>
			</view>
		</view>
		<view class="action">
			<view class="but" style="background-color: #E3C14A;" @click="launchshare">
				<image src="/static/image/wechat.png" class="icon"></image>
				<text>邀请好友助力</text>
			</view>
			<view class="but" style="background-color: #378aff;" @click="shareposer">
				<image src="/static/image/picicon.png" class="icon"></image>
				<text>生成助力海报</text>
			</view>
		</view>
	
		<!--去领取助力红包-->
		<view class="friendbag" v-if="boostdata.help_red_envelope">
			<view class="left">邀请{{boostdata.help_red_envelope_config.help_red_condition}}位好有助力，{{boostdata.help_red_envelope_config.ordinary?'即可领取最高':'即可领取'}}{{boostdata.help_red_envelope_config.help_red_amount}}现金红包</view>
			<view class="right">
				<view class="iconfont">&#xe66c;</view>
				<navigator :url="'/pages/lottery/receivehelpbag?id='+drawid">去领取 ›</navigator>
			</view>
		</view>
		<!--出现口令随机倍数-->
		<view class="friendbag" v-if="boostdata.boost_password">
			<view class="left">输入口令中奖率最高增加<text class="redfont">{{boostdata.boost_multiple}}</text>倍</view>
			<view class="right">
				<view @click="passwords" class="redfont">{{parseInt(passwordmultiple)?'中奖率增加+'+passwordmultiple+'倍':'立即输入 ›'}}</view>
			</view>
		</view>
	</view>
</template>
<script>
	/**
	 * 好友助力组件
	 */
	export default { 
		props: {
			drawid: {
				type: [String, Number],
				default: 0,
			},
			//助力数据
			boostdata:{
				type:Object,
				default:{}
			},
			//是否已参与抽奖
			participated:{
				type:Boolean,
				default:false,
			},
			//中奖倍率
			passwordmultiple:{
				type:[String,Number],
				default:0,
			}
		},
		data() {
			return {
				friend: 5,
				shareinfo: '' ,// 分享信息
				multiple:0,
				helplistdata:[],
			}
		},
		created() {
			this.gethelpuser();
		},
		methods: {
			//获取助力人员
			gethelpuser(){
				this.$HttRequest({
					url: '/lottery/helpDetails',
					param: {
						id: this.drawid
					}
				}).then((res) => {
					console.log(res);
					if (res.status === 10000) {
						this.helplistdata = res.data.helpDetails.data;
						this.multiple = res.data.multiple
					} else {
						this.$ShowMsg(res.message)
					}
				}).catch((error) => {
					//异常错误
					this.$ShowMsg('statusCode：' + error.errMsg);
				})
			},
			
			//输入口令领取红包
			passwords(){
			//console.log(this.passwordmultiple);
				if(this.passwordmultiple>0){
					return;
				}
				this.$emit('openhelppass',true);
			},
			
			//去排行版本
			gotorank() {
				uni.navigateTo({
					url: "/pages/lottery/ranking?id="+this.drawid
				})
			},

			//打开助力好有小提示
			opentip() {
				uni.$emit('openfriendtip', true);
			},
			//获取助力海报
			shareposer() {
				this.$emit('openwechatshare');
			},
			//发起分享
			launchshare() {
				if (this.shareinfo) {
					this.sharefriend(this.shareinfo);
					return;
				}
				this.$HttRequest({
					url: '/lottery/shareImg',
					param: {
						id: this.drawid
					}
				}, 'GET', true).then((res) => {
					console.log(res);
					if (res.status === 10000) {
						this.shareinfo = res.data;
						this.sharefriend(this.shareinfo);
					} else {
						this.$ShowMsg(res.message)
					}
				}).catch((error) => {
					//异常错误
					this.$ShowMsg('statusCode：' + error.errMsg);
				})
			},

			sharefriend(shareinfo) {
				let _this = this
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 0,
					href: shareinfo.url,
					title: shareinfo.sTitle,
					summary: shareinfo.sDescribe,
					imageUrl: shareinfo.sImage,
					success: function(res) {
						_this.$ShowMsg('分享朋友朋友或群成功！')
					},
					fail: function(err) {
						console.log(err);
						_this.$ShowMsg('分享朋友失败！')
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	.swiper{
		font-weight: bold;
		font-size: 32rpx;
		width: 630rpx;
		height: 48rpx;
		margin-left: 20rpx;
	}
	.redfont{
		color: #FF0000;
	}
	.friendbag {
		font-size: 25rpx;
		color: #333;
		display: flex;
		justify-content: space-between;
		padding-top: 20rpx;

		.left {}

		.right {
			font-size: 25rpx;
			color: #f35450;
			display: flex;
			justify-content: center;
			align-items: center;

			.iconfont {
				color: #f35450;
				font-size: 30rpx;

			}
		}
	}

	/* 海报 */
	.action .but image {
		width: 50rpx;
		height: 50rpx;
		margin-right: 10rpx;
	}

	.action .but text {
		font-size: 26rpx;
	}

	.action .but {
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		padding: 20rpx 0;
		border-radius: 200rpx;
		width: 320rpx;
	}

	.action {
		display: flex;
		justify-content: space-around;
		border-bottom: 1rpx solid #f2f2f2;
		padding-bottom: 20rpx;
	}

	/* 列表 */
	.list .item .nickname {
		font-size: small;
		margin-top: 16rpx;
		overflow: hidden;
		width: 117rpx;
		display: inline-block;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-size: 25rpx;
	}

	.list .item .multiple {
		font-size: 18rpx;
		position: absolute;
		top: -11rpx;
		right: -10rpx;
		line-height: 30rpx;
		background-color: red;
		height: 30rpx;
		padding: 0 10rpx;
		color: #fff;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		border-bottom-right-radius: 40rpx;
	}

	.list .item {
		position: relative;
		text-align: center;
		width: 117rpx;
	}

	.list .item image {
		display: block;
		height: 90rpx;
		width: 90rpx;
		margin: 0 auto;
		border-radius: 90rpx;
	}

	.list .item .morefriend {
		display: block;
		height: 80rpx;
		width: 80rpx;
		border-radius: 90rpx;
		background-color: #f4f4f4;
		display: flex;
		justify-content: center;

		font-size: 35rpx;
		color: #898989;
		border: 1rpx dashed #898989;

	}

	.list {
		margin: 40rpx 0;
		display: flex;
		flex-direction: row;
	}

	/* 头部 */
	.title {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.title text {
		font-size: medium;
		font-weight: bold;
	}
</style>
